package edu.sysu.cshare.model;

import java.io.Serializable;
import java.util.Calendar;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

@Entity
@Table(name = "T_HOMEWORK")
public class Homework implements Serializable {

	private long id;
	private String descrip;
	private String dirPath;
	private Calendar dueDate;
	private String extRestrict;
	private int maxSize;
	private String remark;
	private Calendar startDate;
	private boolean submitByGroup;
	private String submitMethod;
	private Course course;
	private List<SubmitInfo> submitInfos;

	@Id
	@GeneratedValue
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	@Column(length = 255)
	public String getDescrip() {
		return descrip;
	}

	public void setDescrip(String descrip) {
		this.descrip = descrip;
	}

	@Column(length = 255)
	public String getDirPath() {
		return dirPath;
	}

	public void setDirPath(String dirPath) {
		this.dirPath = dirPath;
	}

	public Calendar getDueDate() {
		return dueDate;
	}

	public void setDueDate(Calendar dueDate) {
		this.dueDate = dueDate;
	}

	@Column(length = 255)
	public String getExtRestrict() {
		return extRestrict;
	}

	public void setExtRestrict(String extRestrict) {
		this.extRestrict = extRestrict;
	}

	public int getMaxSize() {
		return maxSize;
	}

	public void setMaxSize(int maxSize) {
		this.maxSize = maxSize;
	}

	@Column(length = 255)
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public Calendar getStartDate() {
		return startDate;
	}

	public void setStartDate(Calendar startDate) {
		this.startDate = startDate;
	}

	public boolean getSubmitByGroup() {
		return submitByGroup;
	}

	public void setSubmitByGroup(boolean submitByGroup) {
		this.submitByGroup = submitByGroup;
	}

	@Column(length = 255)
	public String getSubmitMethod() {
		return submitMethod;
	}

	public void setSubmitMethod(String submitMethod) {
		this.submitMethod = submitMethod;
	}

	@ManyToOne
	public Course getCourse() {
		return course;
	}

	public void setCourse(Course course) {
		this.course = course;
	}

	@OneToMany(mappedBy = "homework", cascade = CascadeType.REMOVE, fetch = FetchType.EAGER)
	@Fetch(FetchMode.SUBSELECT)
	public List<SubmitInfo> getSubmitInfos() {
		return submitInfos;
	}

	public void setSubmitInfos(List<SubmitInfo> submitInfos) {
		this.submitInfos = submitInfos;
	}

}
